package com.contory.ssn_lgnd.app.maingame;

import android.util.Log;

import com.contory.ssn_lgnd.app.Assets;
import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.app.comp.ViewObject;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;

public class BarGraphView implements DrawPtr{
	final int MAX_CELL_COUNT;
	ViewObject bodyView;
	//float barCellWidth;
	float strX;
	float rate = 0.9f;
	float whRate;
	int curBarCellCount;
	float r = 1, g = 0, b = 0;
	float paddingX;
	boolean boardVisibleBool = true;
	public BarGraphView(float x, float y, float w, float h, int MAX_CELL_COUNT){
		bodyView = new ViewObject();
		bodyView.setXY_WH_TR(x, y, w, h, Assets.tex_reg_whiteTexel);
		paddingX = ((w - (w * rate)) / 2) - (w / 2);
		strX = x + paddingX;
		whRate = (h / w) * 0.5f;
		this.MAX_CELL_COUNT = MAX_CELL_COUNT;
		curBarCellCount = this.MAX_CELL_COUNT;
	}
	
	public void setBarColor(float r, float g, float b){
		this.r = r; this.g = g; this.b = b;
	}
	
	public void setBoardVisibleBool(boolean boardVisibleBool){
		this.boardVisibleBool = boardVisibleBool;
	}
	
	public void setBarCellCount(int barCellCount){
		if(barCellCount > MAX_CELL_COUNT){
			barCellCount = MAX_CELL_COUNT;
		}
		if(barCellCount < 0){
			barCellCount = 0;
		}
		curBarCellCount = barCellCount;
	}
	
	public void setPos(float x, float y){
		bodyView.x = x; 
		bodyView.y = y;
		strX = bodyView.x + paddingX;
	}
	
	public void addOffsetX(float offsetX){
		strX += offsetX;
		bodyView.x += offsetX;
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		if(boardVisibleBool)
			batcher.drawSprite(bodyView.x, bodyView.y, bodyView.w, bodyView.h, 0, 0, 0, 1, bodyView.tr);
		batcher.drawRightRect(strX, bodyView.y, 
				bodyView.w * rate, 
				bodyView.w * rate * whRate, 
				1, 1, 1, 1, bodyView.tr);
		batcher.drawRightRect(strX, bodyView.y, 
				((float)curBarCellCount / MAX_CELL_COUNT) * bodyView.w * rate,
				bodyView.w * rate * whRate, 
				r, g, b, 1, bodyView.tr);
	}
}
